/**
 * 
 */
package com.google.code.head2head.gwtmodules.client.dto;

import java.util.Date;
import java.util.Iterator;
import java.util.Set;

import com.google.gwt.user.client.rpc.IsSerializable;

/**
 * 
 * @author Eric Bellard - bellard@supagro.inra.fr Copyright © 2007 INRA. All
 *         rights reserved.
 */
public class Entry implements IsSerializable{
	
	private Long id;
	private String fistImageUrl;
	private String secondImageUrl;
	private WebUser user;
	private String description;
	private String title;
	private String language;
	private Date date;
	private Set grades;

	/**
	 * @return the id
	 */
	public Long getId() {
		return id;
	}

	/**
	 * @param id
	 *            the id to set
	 */
	public void setId(Long id) {
		this.id = id;
	}

	/**
	 * @return the fistImageUrl
	 */
	public String getFistImageUrl() {
		return fistImageUrl;
	}

	/**
	 * @param fistImageUrl
	 *            the fistImageUrl to set
	 */
	public void setFistImageUrl(String fistImageUrl) {
		this.fistImageUrl = fistImageUrl;
	}

	/**
	 * @return the secondImageUrl
	 */
	public String getSecondImageUrl() {
		return secondImageUrl;
	}

	/**
	 * @param secondImageUrl
	 *            the secondImageUrl to set
	 */
	public void setSecondImageUrl(String secondImageUrl) {
		this.secondImageUrl = secondImageUrl;
	}

	/**
	 * @return the user
	 */
	public WebUser getUser() {
		return user;
	}

	/**
	 * @param user
	 *            the user to set
	 */
	public void setUser(WebUser user) {
		this.user = user;
	}

	/**
	 * @return the description
	 */
	public String getDescription() {
		return description;
	}

	/**
	 * @param description
	 *            the description to set
	 */
	public void setDescription(String description) {
		this.description = description;
	}

	/**
	 * @return the title
	 */
	public String getTitle() {
		return title;
	}

	/**
	 * @param title
	 *            the title to set
	 */
	public void setTitle(String title) {
		this.title = title;
	}

	/**
	 * @return the language
	 */
	public String getLanguage() {
		return language;
	}

	/**
	 * @param language
	 *            the language to set
	 */
	public void setLanguage(String language) {
		this.language = language;
	}

	/**
	 * @return the date
	 */
	public Date getDate() {
		return date;
	}

	/**
	 * @param date
	 *            the date to set
	 */
	public void setDate(Date date) {
		this.date = date;
	}

	public Set getGrades() {
		return grades;
	}

	public void setGrades(Set grades) {
		this.grades = grades;
	}

	/**
	 * 
	 * @return the mean rating for this entry or -1 if no rating
	 */
	public float getMeanRating(){
		if(grades!=null&&grades.size()>0){
			int total=0;
			float i=0;
			for (Iterator iterator = grades.iterator(); iterator.hasNext();) {
				Grade grade = (Grade) iterator.next();
				total+=grade.getGrade();
				i+=1;
			}
			float result=total/i;
			return result;
		}
		else return -1;
	}
	
}
